<!DOCTYPE html>
<uieip type="page" value="login" debug="true" timeout="5000"></uieip>
<uieip type="reg" value="console,model" />
<html>

<head>
    <meta charset="UTF-8">
    <title>股票指标图表 - </title>

    <script src="/adp/stock/js/highcharts/highstock.js"></script>
    <script src="/adp/stock/js/highcharts/modules/exporting.js"></script>
    <script src="/adp/stock/js/highcharts/indicators/indicators.js"></script>
    <script src="/adp/stock/js/highcharts/indicators/ichimoku-kinko-hyo.js"></script>
    <script src="/adp/stock/js/highcharts/modules/drag-panes.js"></script>
    <script src="/adp/stock/js/highcharts/modules/annotations-advanced.js"></script>
    <script src="/adp/stock/js/highcharts/modules/price-indicator.js"></script>
    <script src="/adp/stock/js/highcharts/modules/full-screen.js"></script>
    <script src="/adp/stock/js/highcharts/modules/stock-tools.js"></script>
    <script src="/adp/stock/js/highcharts/modules/accessibility.js"></script>

    <uieip type="file" value="inc" src="/yqwin/easyui/include.txt" cache="true" minute="1440"></uieip>
    <uieip type="file" value="css" src="/yqwin/css/yqwin.min"></uieip>
    <uieip type="file" value="js" src="/yqwin/src/yqwin.min"></uieip>
    <script src="/adp/stock/js/pub.js"></script>
    <style>
        body {
            overflow: hidden;
            margin: 0;
            padding: 0;
            font-family: Arial, sans-serif;
        }

        #view_setup_div {
            text-align: right;
            padding: 3px 8px;
        }

        #view_setup_div span.switchbutton {
            margin: 2px;
        }

        #highcharts-chart {
            width: 100%;
            height: 100vh;
        }

        #indicator-controls {
            margin: 0;
            padding: 0 0 0 3px;
            background-color: #f0f0f0;
            border-bottom: 1px solid #ddd;
            display: flex;
            justify-content: space-between;
            align-items: center;
        }

        #indicator-controls td {
            padding: 0 3px;
            margin: 0;
        }

        #btn_refresh {
            padding: 4px 8px;
            background-color: #1463da;
            color: white;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            transition: background-color 0.3s;
        }

        #btn_refresh:hover {
            background-color: #104caa;
            /* 修改悬停颜色 */
        }

        #a_close {
            position: absolute;
            padding: 2px;
            top: 0px;
            right: 0px;
            font-size: 22px;
            color: #aa2210;
        }

        #a_close:hover {
            color: #ff2205;
        }

        text.highcharts-credits {
            display: none;
        }
    </style>
</head>

<body>
    <table id="indicator-controls">
        <tr>
            <td>
                <input id='ck_ma1_toggle' />
                <input id='ck_boll_toggle' />
                <input id='ck_ene_toggle' />
                <input id='ck_ma_toggle' />
            </td>
            <td> <a href="javascript:void(0);" class="pagination-btn-separator"></a></td>
            <td>
                <a href="javascript:void(0)" id="mb" class="easyui-menubutton"
                    data-options="menu:'#view_setup_div',iconCls:'fa fa-line-chart'">图表设置</a>
                <div id="view_setup_div" style="width: 120px;">
                    <input id='ck_view_vol' />
                    <input id='ck_view_macd' />
                    <input id='ck_view_vmacd' />
                    <input id='ck_view_vrsi' />
                    <input id='ck_view_ad' />
                    <input id="ck_view_ser" />
                    <input id="ck_view_pva" />
                    <input id="ck_view_bf" />
                    <input id='ck_view_kdj' />
                    <input id='ck_view_cci' />
                    <input id='ck_view_adx' />
                </div>
            </td>
            <td>
                <a id="btn_setup" title="参数设置" href="javascript:void(0);">参数设置<span class="fa fa-caret-down"></span></a>
            </td>
            <td>
                <a id="view_stockpage" href="https://stockpage.10jqka.com.cn/" class="fa fa-link"
                    target="_blank">同花顺</a>
            </td>
        </tr>
    </table>
    <a id="a_close" class="fa fa-window-close" href="javascript:close_window();" title="关闭窗口"></a>
    <div id="highcharts-chart"></div>
    <script>
        function close_window() {
            $.yqDialog_fun('close');
        }

        var ts_code = stock_pub.urlParams('ts_code') || '600061.SH'; // 若未获取到参数，使用默认值
        console.log('ts_code:', ts_code);
        var svr_response;
        var params = {
            values: {},
            set: function (key, value) {
                this.values[key] = value;
            },
            get: function (key) {
                return this.values[key];
            },
            save: function () {
                localStorage.setItem('stock_view_params', JSON.stringify(params.values));
            },
            load: function () {
                var tmp = localStorage.getItem('stock_view_params');
                if (tmp) {
                    params.values = JSON.parse(tmp);
                }

                params.values = $.extend({
                    ma1_toggle: true,
                    boll_toggle: true,
                    txt_boll: 20,
                    ene_toggle: false,
                    txt_ene_m1: 11,
                    txt_ene_m2: 9,
                    txt_ene_n: 10,
                    ma_toggle: false,
                    txt_ma_long: 8,
                    txt_ma_short: 3,

                    view_vol: true,
                    txt_vol_long: 8,
                    txt_vol_short: 3,

                    view_macd: true,
                    txt_macd_long: 8,
                    txt_macd_short: 3,
                    txt_macd_signal: 5,

                    view_vmacd: true,
                    txt_vmacd_long: 12,
                    txt_vmacd_short: 26,
                    txt_vmacd_signal: 9,

                    view_vrsi: true,
                    txt_vrsi_period: 14,

                    view_ad: true,   //累积派发线

                    view_ser: true,
                    txt_ser_period: 5,

                    view_pva: true,
                    txt_pva_period: 6,

                    view_bf: true,
                    txt_bf_period: 6,

                    view_kdj: true,
                    txt_kdj_period: 9,
                    txt_kdj_kSmooth: 3,
                    txt_kdj_dSmooth: 3,

                    view_cci: true,
                    txt_cci_period: 14,

                    view_adx: true,
                    txt_adx_period: 14,
                }, params.values);
            },
            svr_response: {},
            chart: null,
            toggleSeries: function (seriesName, show) {
                const series = this.chart.get(seriesName);
                if (series) {
                    series.setVisible(show, false);
                    this.chart.redraw();
                } else {
                    console.error(`未找到系列 ${seriesName}`);
                }
            },
            chart_redraw: function () {
                this.is_edit(false);

                params.save();
                chart_draw(this.svr_response);
            },
            is_edit(edit) {
                if (edit) {
                    $("#ck_ma1_toggle").switchbutton("enable");
                    $("#ck_boll_toggle").switchbutton("enable");
                    $("#ck_ene_toggle").switchbutton("enable");
                    $("#ck_ma_toggle").switchbutton("enable");
                    $("#ck_view_vol").switchbutton("enable");
                    $("#ck_view_macd").switchbutton("enable");
                    $("#ck_view_vmacd").switchbutton("enable");
                    $("#ck_view_vrsi").switchbutton("enable");
                    $("#ck_view_ad").switchbutton("enable");
                    $("#ck_view_ser").switchbutton("enable");
                    $("#ck_view_pva").switchbutton("enable");
                    $("#ck_view_bf").switchbutton("enable");
                    $("#ck_view_kdj").switchbutton("enable");
                    $("#ck_view_cci").switchbutton("enable");
                    $("#ck_view_adx").switchbutton("enable");
                    $("#btn_setup").linkbutton("enable");
                } else {
                    $("#ck_ma1_toggle").switchbutton("disable");
                    $("#ck_boll_toggle").switchbutton("disable");
                    $("#ck_ene_toggle").switchbutton("disable");
                    $("#ck_ma_toggle").switchbutton("disable");
                    $("#ck_view_vol").switchbutton("disable");
                    $("#ck_view_macd").switchbutton("disable");
                    $("#ck_view_vmacd").switchbutton("disable");
                    $("#ck_view_vrsi").switchbutton("disable");
                    $("#ck_view_ad").switchbutton("disable");
                    $("#ck_view_ser").switchbutton("disable");
                    $("#ck_view_pva").switchbutton("disable");
                    $("#ck_view_bf").switchbutton("disable");
                    $("#ck_view_kdj").switchbutton("disable");
                    $("#ck_view_cci").switchbutton("disable");
                    $("#ck_view_adx").switchbutton("disable");
                    $("#btn_setup").linkbutton("disable");
                }
            },
            setup: function (btn) {
                var prevent_e = $.getPreventDefault($(btn));
                var mdiinfo = $.yqGetWindParams();
                var w_ = $(document).width() - 20;
                var h_ = $(document).height() - 20;
                var opt = {
                    prevent_e: prevent_e,
                    mdiinfo: mdiinfo,
                    title: "指标参数设置",
                    titles: [
                        {
                            "name": "txt_boll",
                            "ui_title": "N-均线天数",
                            "ui_type": 10,
                            "ui_width": 80,
                            "ui_visible": true,
                            "ui_readonly": false,
                            "ui_mask": {
                                "min": 1,
                                "max": 180,
                                "blank": false,
                                "default": 20
                            },
                            "group": "BOOL"
                        },
                        {
                            "name": "txt_ene_m1",
                            "ui_title": "M1-上轨涨幅的百分比",
                            "ui_type": 10,
                            "ui_width": 80,
                            "ui_visible": true,
                            "ui_readonly": false,
                            "ui_mask": {
                                "min": 1,
                                "max": 180,
                                "blank": false,
                                "default": 11
                            },
                            "group": "ENE"
                        },
                        {
                            "name": "txt_ene_m2",
                            "ui_title": "M2-下轨跌幅的百分比",
                            "ui_type": 10,
                            "ui_width": 80,
                            "ui_visible": true,
                            "ui_readonly": false,
                            "ui_mask": {
                                "default": 9,
                                "min": 1,
                                "max": 180,
                                "blank": false
                            },
                            "group": "ENE"
                        },
                        {
                            "name": "txt_ene_n",
                            "ui_title": "N-均线天数",
                            "ui_type": 10,
                            "ui_width": 80,
                            "ui_visible": true,
                            "ui_readonly": false,
                            "ui_mask": {
                                "default": 10,
                                "min": 1,
                                "max": 180,
                                "blank": false
                            },
                            "group": "ENE"
                        },
                        {
                            "name": "txt_ma_short",
                            "ui_title": "short-均线天数",
                            "ui_type": 10,
                            "ui_width": 80,
                            "ui_visible": true,
                            "ui_readonly": false,
                            "ui_mask": {
                                "default": 8,
                                "min": 1,
                                "max": 180,
                                "blank": false
                            },
                            "group": "Kline-MA"
                        }, {
                            "name": "txt_ma_long",
                            "ui_title": "long-均线天数",
                            "ui_type": 10,
                            "ui_width": 80,
                            "ui_visible": true,
                            "ui_readonly": false,
                            "ui_mask": {
                                "default": 8,
                                "min": 1,
                                "max": 180,
                                "blank": false
                            },
                            "group": "Kline-MA"
                        }, {
                            "name": "txt_vol_short",
                            "ui_title": "short-均线天数",
                            "ui_type": 10,
                            "ui_width": 80,
                            "ui_visible": true,
                            "ui_readonly": false,
                            "ui_mask": {
                                "default": 3,
                                "min": 1,
                                "max": 180,
                                "blank": false
                            },
                            "group": "VOL-MA"
                        },
                        {
                            "name": "txt_vol_long",
                            "ui_title": "long-均线天数",
                            "ui_type": 10,
                            "ui_width": 80,
                            "ui_visible": true,
                            "ui_readonly": false,
                            "ui_mask": {
                                "default": 8,
                                "min": 1,
                                "max": 180,
                                "blank": false
                            },
                            "group": "VOL-MA"
                        },
                        {
                            "name": "txt_macd_short",
                            "ui_title": "短数移动平均线",
                            "ui_type": 10,
                            "ui_width": 80,
                            "ui_visible": true,
                            "ui_readonly": false,
                            "ui_mask": {
                                "default": 10,
                                "min": 1,
                                "max": 180,
                                "blank": false
                            },
                            "group": "MACD"
                        },
                        {
                            "name": "txt_macd_long",
                            "ui_title": "长指数移动平均线",
                            "ui_type": 10,
                            "ui_width": 80,
                            "ui_visible": true,
                            "ui_readonly": false,
                            "ui_mask": {
                                "default": 26,
                                "min": 1,
                                "max": 180,
                                "blank": false
                            },
                            "group": "MACD"
                        }, {
                            "name": "txt_macd_signal",
                            "ui_title": "加权移动均线",
                            "ui_type": 10,
                            "ui_width": 80,
                            "ui_visible": true,
                            "ui_readonly": false,
                            "ui_mask": {
                                "default": 9,
                                "min": 1,
                                "max": 180,
                                "blank": false
                            },
                            "group": "MACD"
                        },
                        {
                            "name": "txt_vmacd_long",
                            "ui_title": "长指数移动平均线",
                            "ui_type": 10,
                            "ui_width": 80,
                            "ui_visible": true,
                            "ui_readonly": false,
                            "ui_mask": {
                                "default": 26,
                                "min": 1,
                                "max": 180,
                                "blank": false
                            },
                            "group": "VMACD"
                        }, {
                            "name": "txt_vmacd_short",
                            "ui_title": "短数移动平均线",
                            "ui_type": 10,
                            "ui_width": 80,
                            "ui_visible": true,
                            "ui_readonly": false,
                            "ui_mask": {
                                "default": 9,
                                "min": 1,
                                "max": 180,
                                "blank": false
                            },
                            "group": "VMACD"
                        }, {
                            "name": "txt_vmacd_signal",
                            "ui_title": "加权移动均线",
                            "ui_type": 10,
                            "ui_width": 80,
                            "ui_visible": true,
                            "ui_readonly": false,
                            "ui_mask": {
                                "default": 9,
                                "min": 1,
                                "max": 180,
                                "blank": false
                            },
                            "group": "VMACD"
                        },
                        {
                            "name": "txt_vrsi_period",
                            "ui_title": "Period",
                            "ui_type": 10,
                            "ui_width": 80,
                            "ui_visible": true,
                            "ui_readonly": false,
                            "ui_mask": {
                                "default": 14,
                                "min": 1,
                                "max": 180,
                                "blank": false
                            },
                            "group": "VRSI"
                        },
                        {
                            "name": "txt_ser_period",
                            "ui_title": "period",
                            "ui_type": 10,
                            "ui_width": 80,
                            "ui_visible": true,
                            "ui_readonly": false,
                            "ui_mask": {
                                "default": 5,
                                "min": 1,
                                "max": 180,
                                "blank": false
                            },
                            "group": "SER"
                        },
                        {
                            "name": "txt_pva_period",
                            "ui_title": "period",
                            "ui_type": 10,
                            "ui_width": 80,
                            "ui_visible": true,
                            "ui_readonly": false,
                            "ui_mask": {
                                "default": 6,
                                "min": 1,
                                "max": 180,
                                "blank": false
                            },
                            "group": "PVA"
                        },
                        {
                            "name": "txt_bf_period",
                            "ui_title": "period",
                            "ui_type": 10,
                            "ui_width": 80,
                            "ui_visible": true,
                            "ui_readonly": false,
                            "ui_mask": {
                                "default": 6,
                                "min": 1,
                                "max": 180,
                                "blank": false
                            },
                            "group": "BF"
                        },
                        {
                            "name": "txt_kdj_kSmooth",
                            "ui_title": "kSmooth",
                            "ui_type": 10,
                            "ui_width": 80,
                            "ui_visible": true,
                            "ui_readonly": false,
                            "ui_mask": {
                                "default": 3,
                                "min": 1,
                                "max": 180,
                                "blank": false
                            },
                            "group": "KDJ"
                        },
                        {
                            "name": "txt_kdj_dSmooth",
                            "ui_title": "dSmooth",
                            "ui_type": 10,
                            "ui_width": 80,
                            "ui_visible": true,
                            "ui_readonly": false,
                            "ui_mask": {
                                "default": 3,
                                "min": 1,
                                "max": 180,
                                "blank": false
                            },
                            "group": "KDJ"
                        },
                        {
                            "name": "txt_cci_period",
                            "ui_title": "period",
                            "ui_type": 10,
                            "ui_width": 80,
                            "ui_visible": true,
                            "ui_readonly": false,
                            "ui_mask": {
                                "default": 14,
                                "min": 1,
                                "max": 180,
                                "blank": false
                            },
                            "group": "CCI"
                        },
                        {
                            "name": "txt_cci_period",
                            "ui_title": "period",
                            "ui_type": 10,
                            "ui_width": 80,
                            "ui_visible": true,
                            "ui_readonly": false,
                            "ui_mask": {
                                "default": 14,
                                "min": 1,
                                "max": 180,
                                "blank": false
                            },
                            "group": "CCI"
                        },
                    ],
                    action: "add",
                    row: params.values,
                    isEdit: true,
                    loadDefault: false,   //加载默认值
                    blankTag: "*",     //值不能为空，标题附加标记
                    removeUnUse: false,
                    width: 600,
                    height: 420,
                    horizontalAlign: "none",
                    verticalAlign: "none",
                    callback: function (row) {
                        console.log('回调:', row);
                        params.values = row;
                        params.chart_redraw();
                    },
                };
                if (window.top == window.self) {
                    $.yqAttrPopEdit(opt);
                }
                else {
                    window.top.$.yqAttrPopEdit(opt);
                }
            }
        };

        $(function () {
            params.load();

            $("#ck_ma1_toggle").switchbutton({
                width: "100",
                height: "25",
                onText: "ON",
                offText: "OFF",
                handleText: 'MA1',
                handleWidth: '65',
                checked: params.values.ma1_toggle,
                disabled: true,
                onChange: function (checked) {
                    params.values.ma1_toggle = checked;
                    params.save();

                    console.log('ma1 切换:', checked);
                    params.toggleSeries('ma_day', checked);
                }
            })
            $("#ck_boll_toggle").switchbutton({
                width: "100",
                height: "25",
                onText: "ON",
                offText: "OFF",
                handleText: 'BOOL',
                handleWidth: '65',
                checked: params.values.boll_toggle,
                disabled: true,
                onChange: function (checked) {
                    params.values.boll_toggle = checked;
                    params.save();

                    console.log('布林带 切换:', checked);
                    params.toggleSeries('BOLL-MID', checked);
                    params.toggleSeries('BOLL-UPPER', checked);
                    params.toggleSeries('BOLL-LOWER', checked);
                }
            });
            $("#ck_ene_toggle").switchbutton({
                width: "100",
                height: "25",
                onText: "ON",
                offText: "OFF",
                handleText: 'ENE',
                handleWidth: '65',
                checked: params.values.ene_toggle,
                disabled: true,
                onChange: function (checked) {
                    params.values.ene_toggle = checked;
                    params.save();

                    console.log('ENE 切换:', checked);
                    params.toggleSeries('ENE-MID', checked);
                    params.toggleSeries('ENE-UPPER', checked);
                    params.toggleSeries('ENE-LOWER', checked);
                }
            });
            $("#ck_ma_toggle").switchbutton({
                width: "100",
                height: "25",
                onText: "ON",
                offText: "OFF",
                handleText: 'MA',
                handleWidth: '65',
                checked: params.values.ma_toggle,
                disabled: true,
                onChange: function (checked) {
                    params.values.ma_toggle = checked;
                    params.save();

                    console.log('ma_short 切换:', checked);
                    params.toggleSeries('ma_short', checked);
                    params.toggleSeries('ma_long', checked);
                }
            })
            $("#ck_view_vol").switchbutton({
                width: "100",
                height: "25",
                onText: "ON",
                offText: "OFF",
                handleText: 'VOL',
                handleWidth: '65',
                checked: params.values.view_vol,
                disabled: true,
                onChange: function (checked) {
                    params.values.view_vol = checked;
                    params.chart_redraw();
                }
            });
            $("#ck_view_macd").switchbutton({
                width: "100",
                height: "25",
                onText: "ON",
                offText: "OFF",
                handleText: 'MACD',
                handleWidth: '65',
                disabled: true,
                checked: params.values.view_macd,
                onChange: function (checked) {
                    params.values.view_macd = checked;
                    params.chart_redraw();
                }
            });
            $("#ck_view_vmacd").switchbutton({
                width: "100",
                height: "25",
                onText: "ON",
                offText: "OFF",
                handleText: 'VMACD',
                handleWidth: '65',
                checked: params.values.view_vmacd,
                disabled: true,
                onChange: function (checked) {
                    params.values.view_vmacd = checked;
                    params.chart_redraw();
                }
            });
            $("#ck_view_vrsi").switchbutton({
                width: "100",
                height: "25",
                onText: "ON",
                offText: "OFF",
                handleText: 'VRSI',
                handleWidth: '65',
                checked: params.values.view_vrsi,
                disabled: true,
                onChange: function (checked) {
                    params.values.view_vrsi = checked;
                    params.chart_redraw();
                }
            });
            $("#ck_view_ad").switchbutton({
                width: "100",
                height: "25",
                onText: "ON",
                offText: "OFF",
                handleText: 'AD',
                handleWidth: '65',
                checked: params.values.view_ad,
                disabled: true,
                onChange: function (checked) {
                    params.values.view_ad = checked;
                    params.chart_redraw();
                }
            });
            $("#ck_view_ser").switchbutton({
                width: "100",
                height: "25",
                onText: "ON",
                offText: "OFF",
                handleText: 'SER',
                handleWidth: '65',
                checked: params.values.view_ser,
                disabled: true,
                onChange: function (checked) {
                    params.values.view_ser = checked;
                    params.chart_redraw();
                }
            });
            $("#ck_view_pva").switchbutton({
                width: "100",
                height: "25",
                onText: "ON",
                offText: "OFF",
                handleText: 'PVA',
                handleWidth: '65',
                checked: params.values.view_pva,
                disabled: true,
                onChange: function (checked) {
                    params.values.view_pva = checked;
                    params.chart_redraw();
                }
            });
            $("#ck_view_bf").switchbutton({
                width: "100",
                height: "25",
                onText: "ON",
                offText: "OFF",
                handleText: 'BF',
                handleWidth: '65',
                checked: params.values.view_bf,
                disabled: true,
                onChange: function (checked) {
                    params.values.view_bf = checked;
                    params.chart_redraw();
                }
            });
            $("#ck_view_kdj").switchbutton({
                width: "100",
                height: "25",
                onText: "ON",
                offText: "OFF",
                handleText: 'KDJ',
                handleWidth: '65',
                checked: params.values.view_kdj,
                disabled: true,
                onChange: function (checked) {
                    params.values.view_kdj = checked;
                    params.chart_redraw();
                }
            });
            $("#ck_view_cci").switchbutton({
                width: "100",
                height: "25",
                onText: "ON",
                offText: "OFF",
                handleText: 'CCI',
                handleWidth: '65',
                checked: params.values.view_cci,
                disabled: true,
                onChange: function (checked) {
                    params.values.view_cci = checked;
                    params.chart_redraw();
                }
            })
            $("#ck_view_adx").switchbutton({
                width: "100",
                height: "25",
                onText: "ON",
                offText: "OFF",
                handleText: 'ADX',
                handleWidth: '65',
                checked: params.values.view_adx,
                disabled: true,
                onChange: function (checked) {
                    params.values.view_adx = checked;
                    params.chart_redraw();
                }
            })

            $("#btn_setup").linkbutton({
                iconCls: 'fa fa-cog',
                plain: true,
                disabled: true,
                onClick: function () {
                    params.setup(this);
                }
            })

            stock_pub.fetchStockData(ts_code, function (response) {
                params.svr_response = response;
                chart_draw(params.svr_response);
            });
        });

        //获取金叉死叉点
        function crossPoints(shortLine, longLine) {
            const _plotLines = [];
            //for (let i = longLine.length-1; i >1; i--) {
            for (let i = 1; i < longLine.length; i++) {
                var crossType = checkCrossType(shortLine, longLine, longLine[i][0]);
                if (crossType == 0) {
                    continue;
                }

                _plotLines.push([
                    longLine[i][0],
                    crossType,
                    stock_pub.formatYYYYMMDD(new Date(longLine[i][0]))
                ]);
            }

            return _plotLines;
        }

        // 判断金叉的函数 1-金叉 -1-死叉 0-无
        function checkCrossType(shortLine, longLine, timestamp) {
            index_short = -1;
            index_long = -1;
            for (let i = 0; i < shortLine.length; i++) {
                if (shortLine[i][0] === timestamp) {
                    index_short = i;
                    break;
                }
            }

            for (let i = 0; i < longLine.length; i++) {
                if (longLine[i][0] === timestamp) {
                    index_long = i;
                    break;
                }
            }

            if (index_short < 1 || index_long < 1) {
                return 0; // 数据不足
            }
            if (shortLine[index_short][1] === null || longLine[index_long][1] === null ||
                shortLine[index_short - 1][1] === null || longLine[index_long - 1][1] === null) {
                return 0; // 数据不足
            }

            var cross_type = 0;
            if (shortLine[index_short][1] > longLine[index_long][1] && shortLine[index_short - 1][1] < longLine[index_long - 1][1]) {
                cross_type = 1;
            } else if (shortLine[index_short][1] < longLine[index_long][1] && shortLine[index_short - 1][1] > longLine[index_long - 1][1]) {
                cross_type = -1;
            } else {
                cross_type = 0; // 无
            }

            // if (cross_type != 0) {
            //     var cross_type_1 = cross_type;
            //     var i = 0;
            //     while (cross_type_1 != 0) {
            //         i++;
            //         if (index_short - i < 1 || index_long - i < 1) {
            //             break;
            //         }

            //         if (shortLine[index_short - i][1] > longLine[index_long - i][1] && shortLine[index_short - 1 - i][1] < longLine[index_long - 1 - i][1]) {
            //             cross_type_1 = 1;
            //         } else if (shortLine[index_short - i][1] < longLine[index_long - i][1] && shortLine[index_short - 1 - i][1] > longLine[index_long - 1 - i][1]) {
            //             cross_type_1 = -1;
            //         } else {
            //             cross_type_1 = 0; // 无
            //         }

            //         if (cross_type_1 != 0) {
            //             cross_type = 0;
            //             break;
            //         }
            //     }
            // }

            return cross_type;
        }


        // 在 chart_draw 函数中调用 MACD 计算
        function chart_draw(response) {
            if (response.rows_2 === undefined) {
                response.rows_2 = [];
            }

            params.is_edit(false);

            console.log('原始数据:', response); // 调试日志

            // 严格验证并转换数据格式
            const ohlc = [];
            const volume = [];
            const volume_2 = [];
            const volume_3 = {
                sm: [], //买入小单  buy_sm_vol
                md: [], //买入中单   buy_md_vol
                lg: [], //买入大单  buy_lg_vol+buy_elg_vol
                sm2: [], //卖出小单  buy_sm_vol
                md2: [], //卖出中单   buy_md_vol
                lg2: [] //卖出大单  buy_lg_vol+buy_elg_vol
            };
            const indicators = response.indicators || [];

            //日线
            const ma_day = [];

            const color_isUp = '#ff3232';
            const color_isDown = '#2b908f';// 上涨红色，下跌绿色
            // 转换K线数据
            response.rows.forEach((k, index) => {
                // 修正日期转换逻辑，确保日期正确
                const year = parseInt(k.trade_date.slice(0, 4));
                const month = parseInt(k.trade_date.slice(4, 6)) - 1;
                const day = parseInt(k.trade_date.slice(6, 8));
                if (isNaN(year) || isNaN(month) || isNaN(day)) return;
                const date = new Date(Date.UTC(year, month, day));
                const timestamp = date.getTime();
                if (isNaN(timestamp)) return;

                ohlc.push([
                    timestamp,
                    parseFloat(k.open),
                    parseFloat(k.high),
                    parseFloat(k.low),
                    parseFloat(k.close),
                    parseInt(k.vol)
                ]);

                ma_day.push([
                    timestamp,
                    parseFloat(k.open)
                ]);

                if (params.values.view_vol && k.vol) {
                    // 判断收盘价是否高于开盘价
                    const isUp = parseFloat(k.close) >= parseFloat(k.open);
                    volume.push({
                        x: timestamp,
                        y: parseInt(k.vol),
                        color: isUp ? color_isUp : color_isDown // 上涨红色，下跌绿色
                    });

                    volume_2.push([
                        timestamp,
                        parseInt(k.vol)
                    ]);
                }
            });

            const ohlc_data = [];
            ohlc.forEach((k, index) => {
                var color = '#000000';
                var lineColor = '#000000';
                if (k[4] >= k[1]) {// 上涨红色，下跌绿色
                    color = '#ffffff';
                    lineColor = '#ff3232';
                    if (index > 0 && calculate.checkLimitStatus(ohlc[index - 1][4], ohlc[index][4]) == 1) {
                        lineColor = '#ffcc00';
                    }
                } else {
                    color = '#2b908f';
                    if (index > 0 && calculate.checkLimitStatus(ohlc[index - 1][4], ohlc[index][4]) == -1) {
                        color = '#00cc33';
                    }
                    lineColor = color;
                }
                ohlc_data.push({
                    x: k[0],
                    open: k[1],
                    high: k[2],
                    low: k[3],
                    close: k[4],
                    volume: k[5],
                    color: color, // 上涨红色，下跌绿色
                    lineColor: lineColor // 上涨红色，下跌绿色
                })
            });

            if (params.values.view_vol) {
                response.rows_2.forEach((k, index) => {
                    // 修正日期转换逻辑，确保日期正确
                    const year = parseInt(k.trade_date.slice(0, 4));
                    const month = parseInt(k.trade_date.slice(4, 6)) - 1;
                    const day = parseInt(k.trade_date.slice(6, 8));
                    if (isNaN(year) || isNaN(month) || isNaN(day)) return;
                    const date = new Date(Date.UTC(year, month, day));
                    const timestamp = date.getTime();
                    if (isNaN(timestamp)) return;

                    //
                    var color = '#000000';
                    for (var i = 0; i < volume.length; i++) {
                        var k1 = volume[i];
                        if (k1.x == timestamp) {
                            color = k1.color; // 上涨红色
                            break;
                        }
                    }

                    volume_3.sm.push({
                        x: timestamp,
                        y: (k.buy_sm_vol),
                        color: color == color_isUp ? "#f36838" : "#00e500",
                    });
                    volume_3.md.push({
                        x: timestamp,
                        y: k.buy_md_vol,
                        color: color == color_isUp ? "#ff3300" : "#00bc12"
                    });
                    volume_3.lg.push({
                        x: timestamp,
                        y: k.buy_lg_vol + k.buy_elg_vol,
                        color: color == color_isUp ? "#c3272b" : "#0c8918"
                    });

                    volume_3.sm2.push({
                        x: timestamp,
                        y: (k.sell_sm_vol),
                        color: color == color_isUp ? "#f36838" : "#00e500",
                    });
                    volume_3.md2.push({
                        x: timestamp,
                        y: k.sell_md_vol,
                        color: color == color_isUp ? "#ff3300" : "#00bc12"
                    });
                    volume_3.lg2.push({
                        x: timestamp,
                        y: k.sell_lg_vol + k.sell_elg_vol,
                        color: color == color_isUp ? "#c3272b" : "#0c8918"
                    });
                });
            }

            const ma_short_Line = calculate.MA(ohlc, params.values.txt_ma_short);
            const ma_long_Line = calculate.MA(ohlc, params.values.txt_ma_long);

            let volume_short_Line = [];
            let volume_long_Line = [];
            // 计算MA
            if (params.values.view_vol) {
                volume_short_Line = calculate.MA(volume_2, params.values.txt_vol_short, 1);
                volume_long_Line = calculate.MA(volume_2, params.values.txt_vol_long, 1);
            }

            // 3. 计算EXPMA(指数平均数)
            // 计算ENE指标 国内:M1 = 11, M2 = 9, N = 10
            /*
               依据：早期国内投资者认为A股的涨跌停幅度为10%，因此将上轨设定为10日均线上浮11%（对应涨停后的价格），
               下轨为下浮9%（对应跌停后的价格）。例如，若10日均线为10元，上轨为10元×1.11=11.1元，下轨为10元×0.91=9.1元
            */
            const ene = calculate.ENE(ohlc, params.values.txt_ene_m1, params.values.txt_ene_m2, params.values.txt_ene_n, 4);
            // 计算并验证ENE指标
            const validENE = ene.filter(point => point[0] && point[1] && point[2] && point[3]);

            // 计算布林带指标
            const boll = calculate.BOLL(ohlc, params.txt_boll, 1);
            const validBOLL = boll.filter(point => point[0] && point[1] && point[2] && point[3]);

            // 计算MACD指标
            let macd = {
                macdLine: [],
                signalLine: [],
                histogram: []
            };
            let macd_histogram = [];
            if (params.values.view_macd) {
                macd = calculate.calculateMACD(ohlc, params.txt_macd_short, params.txt_macd_long, params.txt_macd_signal, 4);
            }
            for (let i = 0; i < macd.histogram.length; i++) {
                macd_histogram.push({
                    x: macd.histogram[i][0],
                    y: macd.histogram[i][1],
                    color: macd.histogram[i][1] > 0 ? '#ff3232' : '#2b908f' // 上涨红色，下跌绿色
                });
            }
            //}

            // 计算VMACD指标
            let vmacd = {
                macdLine: [],
                signalLine: [],
                histogram: []
            };
            let vmacd_histogram = [];
            //if (params.values.view_vmacd) {
            vmacd = calculate.calculateMACD(ohlc, params.txt_vmacd_short, params.txt_vmacd_long, params.txt_vmacd_signal, 5);
            //}
            for (let i = 0; i < vmacd.histogram.length; i++) {
                vmacd_histogram.push({
                    x: vmacd.histogram[i][0],
                    y: vmacd.histogram[i][1],
                    color: vmacd.histogram[i][1] > 0 ? '#ff3232' : '#2b908f' // 上涨红色，下跌绿色
                });
            }

            // 计算VRSI指标
            let vrsi = [];
            //if (params.values.view_vrsi) {
            vrsi = calculate.calculateRSI(ohlc, params.values.txt_vrsi_period || 14, true);// 默认为 14 周期
            //}

            // 计算SER指标
            let ser = [];
            if (params.values.view_ser) {
                ser = calculate.calculateSER(ohlc, params.values.txt_ser_period || 5);// 默认为 5 周期
            }

            // 计算PVA指标
            let pva = [];
            if (params.values.view_pva) {
                pva = calculate.calculatePVA(ohlc, params.values.txt_pva_period || 6);// 默认为 6 周期
            }

            // 计算BF指标
            let bf = [];
            if (params.values.view_bf) {
                bf = calculate.calculateBF(ohlc, params.values.txt_bf_period || 6);// 默认为 6 周期
            }

            //console.log('vrsi:', vrsi); // 调试日志

            // 计算AD指标
            let ad = [];
            //if (params.values.view_ad) {
            ad = calculate.calculateAD(ohlc);
            //}

            //console.log('ad:', ad); // 调试日志

            // 计算KDJ指标
            let kdj = [];
            let kLine = [];
            let dLine = [];
            let jLine = [];
            if (params.values.view_kdj) {
                kdj = calculate.calculateKDJ(ohlc, params.txt_kdj_period, params.txt_kdj_kSmooth, params.txt_kdj_dSmooth, 4);
                kLine = kdj.filter(item => item).map(item => [item.x, item.K]);
                dLine = kdj.filter(item => item).map(item => [item.x, item.D]);
                jLine = kdj.filter(item => item).map(item => [item.x, item.J]);
            }

            // 计算 CCI 指标
            let cciPeriodLine = [];
            if (params.values.view_cci) {
                cciPeriodLine = calculate.calculateCCI(ohlc, params.values.txt_cci_period || 14);// 默认为 14 周期
            }

            // 计算 ADX 指标
            let adxPeriodLine = [];
            if (params.values.view_adx) {
                adxPeriodLine = calculate.calculateADX(ohlc, params.values.txt_adx_period || 14);// 默认为 14 周期
            }

            //计算金叉死叉
            let plotLines = [];
            let plotLines_ = [];

            let plotLines_tmp = [];
            //交易价格
            var _plotLines = [];
            _plotLines = crossPoints(ma_short_Line, ma_long_Line);
            for (let i = 0; i < _plotLines.length; i++) {
                var date = stock_pub.formatYYYYMMDD(new Date(_plotLines[i][0]));
                if (_plotLines[i][1] == 1) {
                    plotLines_tmp.push([_plotLines[i][0], _plotLines[i][1], 1, false, date]);
                } else {
                    plotLines_tmp.push([_plotLines[i][0], _plotLines[i][1], 1, false, date]);
                }
            }
            //按时间排序
            plotLines_tmp.sort((a, b) => a[0] - b[0]);

            for (let i = 0; i < plotLines_tmp.length; i++) {
                var date = stock_pub.formatYYYYMMDD(new Date(plotLines_tmp[i][0]));

                const vmacd_data = calculate.getEndDatasByDate(vmacd.macdLine, plotLines_tmp[i][0], 3);
                const vmacd_data2 = calculate.getEndDatasByDate(vmacd.signalLine, plotLines_tmp[i][0], 3);
                var vmacd_num = 0;
                var vmacd_signal = 0;
                if (vmacd_data.length > 0) {
                    vmacd_num = vmacd_data[vmacd_data.length - 1][1];
                }
                if (vmacd_data2.length > 0) {
                    vmacd_signal = vmacd_data2[vmacd_data2.length - 1][1];
                }

                const vrsi_data = calculate.getEndDatasByDate(vrsi, plotLines_tmp[i][0], 3);
                var vrsi_num_1 = 0;
                var vrsi_num_2 = 0;
                if (vrsi_data.length > 1) {
                    vrsi_num_1 = vrsi_data[vrsi_data.length - 1][1];
                    vrsi_num_2 = vrsi_data[vrsi_data.length - 2][1];
                }

                const ad_data = calculate.getEndDatasByDate(ad, plotLines_tmp[i][0], 3);
                var ad_num_1 = 0;
                var ad_num_2 = 0;
                if (ad_data.length > 1) {
                    ad_num_1 = ad_data[ad_data.length - 1][1];
                    ad_num_2 = ad_data[ad_data.length - 2][1];
                }

                if (plotLines_tmp[i][1] == 1) {
                    if (plotLines_tmp[i][2] == 1) {
                        var buy = false;
                        //if (vmacd_num > 0 && vmacd_num > vmacd_signal) {
                        //if (vmacd_num > vmacd_signal &&
                        if ((vmacd_num > vmacd_signal &&
                            (vrsi_num_1 > vrsi_num_2 || ad_num_1 > ad_num_2) ||
                            (vmacd_num < vmacd_signal &&
                                (vrsi_num_1 > vrsi_num_2 && ad_num_1 > ad_num_2))
                        )) {
                            // if (vmacd_num > vmacd_signal) {
                            buy = true;
                        }
                        plotLines_.push([plotLines_tmp[i][0], plotLines_tmp[i][1], plotLines_tmp[i][2], buy, date, vmacd_num, vmacd_signal, vrsi_num_1, vrsi_num_2, ad_num_1, ad_num_2]);
                    } else {
                        plotLines_.push([plotLines_tmp[i][0], plotLines_tmp[i][1], plotLines_tmp[i][2], false, date, vmacd_num, vmacd_signal, vrsi_num_1, vrsi_num_2, ad_num_1, ad_num_2]);
                    }
                } else {
                    plotLines_.push([plotLines_tmp[i][0], plotLines_tmp[i][1], plotLines_tmp[i][2], plotLines_tmp[i][3], date, vmacd_num, vmacd_signal, vrsi_num_1, vrsi_num_2, ad_num_1, ad_num_2]);
                }
            }

            console.log('plotLines_:', plotLines_); // 调试日志

            /*
            for (let i = 0; i < ohlc.length; i++) {
                const vmacd_data = calculate.getEndDatasByDate(vmacd.macdLine, ohlc[i][0], 3);
                const vmacd_data2 = calculate.getEndDatasByDate(vmacd.signalLine, ohlc[i][0], 3);
                var vmacd_num = 0;
                var vmacd_signal = 0;
                if (vmacd_data.length > 0) {
                    vmacd_num = vmacd_data[vmacd_data.length - 1][1];
                }
                if (vmacd_data2.length > 0) {
                    vmacd_signal = vmacd_data2[vmacd_data2.length - 1][1];
                }

                const vrsi_data = calculate.getEndDatasByDate(vrsi, ohlc[i][0], 3);
                var vrsi_num_1 = 0;
                var vrsi_num_2 = 0;
                if (vrsi_data.length > 1) {
                    vrsi_num_1 = vrsi_data[vrsi_data.length - 2][1];
                    vrsi_num_2 = vrsi_data[vrsi_data.length - 1][1];
                }

                const ad_data = calculate.getEndDatasByDate(ad, ohlc[i][0], 3);
                var ad_num_1 = 0;
                var ad_num_2 = 0;
                if (ad_data.length > 1) {
                    ad_num_1 = ad_data[ad_data.length - 1][1];
                    ad_num_2 = ad_data[ad_data.length - 2][1];
                }

                const ma_short_row = calculate.getSelectByDate(ma_short_Line, ohlc[i][0], 3);
                const ma_long_row = calculate.getSelectByDate(ma_long_Line, ohlc[i][0], 3);

                // if ((vmacd_num > 0 && vmacd_num > vmacd_signal) &&
                //     vrsi_num_1 > vrsi_num_2 &&
                //     ad_num_1 > ad_num_2
                // ) {   //买入点

                if (ohlc[i][4] < ma_short_row[1]
                    && (vmacd_num > 0 && vmacd_num > vmacd_signal)
                    && vrsi_num_1 > vrsi_num_2
                    && ad_num_1 > ad_num_2
                ) {   //买入点
                    plotLines.push({
                        color: '#FFA500', // 金色
                        width: 3, // 线宽
                        value: ohlc[i][0], // 交点的y值
                    })
                }
            }
           */

            for (let i = 0; i < plotLines_.length; i++) {
                if (plotLines_[i][1] == 1) {   //金叉
                    plotLines.push({
                        color: plotLines_[i][3] ? '#e74c3c' : '#e59866', // 金色
                        width: plotLines_[i][3] ? 3 : 1, // 线宽
                        value: plotLines_[i][0], // 交点的y值
                        label: {
                            text: plotLines_[i][2] == 1 ? 'VMACD柱' + (plotLines_[i][5].toFixed(4) +
                                '<br/>VMACD信号线:' + plotLines_[i][6].toFixed(4) +
                                '<br/>VRSI当前:' + plotLines_[i][7].toFixed(4) +
                                '<br/>VRSI前一天:' + plotLines_[i][8].toFixed(4) +
                                '<br/>AD当前:' + plotLines_[i][9].toFixed(4) +
                                '<br/>AD前一天:' + plotLines_[i][10].toFixed(4)) : "2",
                            align: 'center',
                            verticalAlign: 'top',
                            rotation: 0,
                            y: 0
                        }
                    })
                } else if (plotLines_[i][1] == -1) {
                    plotLines.push({
                        color: plotLines_[i][3] ? '#145a32' : '#82E0AA', // 黑色
                        width: plotLines_[i][3] ? 3 : 1, // 线宽
                        value: plotLines_[i][0], // 交点的y值
                        label: {
                            text: plotLines_[i][2],
                            align: 'center',
                            verticalAlign: 'top',
                            rotation: 0,
                            y: 0
                        }
                    })
                }
            }

            var view_num = 0;
            var chart_height = 0;
            if (params.values.view_vol) {
                view_num++;
            }
            if (params.values.view_macd) {
                view_num++;
            }
            if (params.values.view_vmacd) {
                view_num++;
            }
            if (params.values.view_vrsi) {
                view_num++;
            }
            if (params.values.view_rsi) {
                view_num++;
            }
            if (params.values.view_ad) {
                view_num++;
            }
            if (params.values.view_ser) {
                view_num++;
            }
            if (params.values.view_pva) {
                view_num++;
            }
            if (params.values.view_bf) {
                view_num++;
            }
            if (params.values.view_kdj) {
                view_num++;
            }
            if (params.values.view_cci) {
                view_num++;
            }
            if (params.values.view_adx) {
                view_num++;
            }

            if (view_num == 1) {
                chart_height = 40;
            } else if (view_num == 2) {
                chart_height = 30;
            } else if (view_num == 3) {
                chart_height = 20;
            } else if (view_num == 4) {
                chart_height = 16;
            } else if (view_num == 5) {
                chart_height = 14;
            } else if (view_num == 6) {
                chart_height = 12;
            } else if (view_num == 7) {
                chart_height = 11;
            } else if (view_num == 8) {
                chart_height = 10;
            } else if (view_num == 8) {
                chart_height = 8;
            } else if (view_num == 9) {
                chart_height = 8;
            } else if (view_num == 10) {
                chart_height = 8;
            } else if (view_num == 11) {
                chart_height = 7;
            }

            var chart_paras = {
                chart: {
                    type: 'candlestick',
                    zoomType: 'x'
                },
                rangeSelector: {
                    selected: 1,
                    inputEnabled: false
                },
                // title: {
                //     text: response.name + '(' + response.ts_code + ')'
                // },

                rangeSelector: {
                    selected: 2
                },

                series: [{
                    type: 'candlestick',
                    data: ohlc_data,
                    lineWidth: 2,
                    dataGrouping: {
                        enabled: false
                    },
                    turboThreshold: 0,
                    id: 'kline'
                }, {
                    type: 'line',
                    name: 'MA day',
                    data: ma_day,
                    color: '#1C86EE',  // 颜色：蓝色
                    lineWidth: 2,
                    id: 'ma_day',
                }, {
                    type: 'line',
                    name: 'MA short',
                    data: ma_short_Line,
                    color: '#FFA500',  // 颜色：橙色
                    lineWidth: 2,
                    id: 'ma_short'
                }, {
                    type: 'line',
                    name: 'MA long',
                    data: ma_long_Line,
                    color: '#0F0F0F',  // 颜色：黑色
                    lineWidth: 2,
                    id: 'ma_long'
                }, {
                    type: 'line',
                    name: 'ENE MID',
                    data: validENE.map(point => [point[0], point[1]]),
                    color: '#008000',  // 颜色：深绿色
                    lineWidth: 2,
                    id: 'ENE-MID',
                    dashStyle: 'Dash',
                }, {
                    type: 'line',
                    name: 'ENE UPPER',
                    data: validENE.map(point => [point[0], point[2]]),
                    color: '#FF0000',  // 颜色：红色
                    lineWidth: 2,
                    id: 'ENE-UPPER',
                    dashStyle: 'Dash',
                }, {
                    type: 'line',
                    name: 'ENE LOWER',
                    data: validENE.map(point => [point[0], point[3]]),
                    color: '#0000FF',  // 颜色：蓝色
                    lineWidth: 2,
                    id: 'ENE-LOWER',
                    dashStyle: 'Dash',
                }, {
                    type: 'line',
                    name: 'BOLL MID',
                    data: validBOLL.map(point => [point[0], point[1]]),
                    color: '#000000',  // 颜色：黑色
                    lineWidth: 2,
                    dashStyle: 'Dash',
                    id: 'BOLL-MID'
                }, {
                    type: 'line',
                    name: 'BOLL UPPER',
                    data: validBOLL.map(point => [point[0], point[2]]),
                    color: '#FFA500',  // 颜色：橙色
                    lineWidth: 2,
                    dashStyle: 'Dash',
                    id: 'BOLL-UPPER'
                }, {
                    type: 'line',
                    name: 'BOLL LOWER',
                    data: validBOLL.map(point => [point[0], point[3]]),
                    color: '#00FF00',  // 颜色：绿色
                    lineWidth: 2,
                    dashStyle: 'Dash',
                    id: 'BOLL-LOWER'
                }],
                xAxis: {
                    lineWidth: 2, // 设置 x 轴线条宽度
                    tickWidth: 2, // 设置刻度线宽度
                    plotLines: plotLines,
                    // 添加日期轴显示范围
                    min: ohlc[0][0],
                    max: ohlc[ohlc.length - 1][0],
                },
                yAxis: [{
                    labels: {
                        align: 'right',
                        x: -3
                    },
                    title: {
                        text: '价格'
                    },
                    height: (100 - chart_height * view_num) + '%',
                    lineWidth: 2
                }],
                tooltip: {
                    split: true
                },
                navigator: {
                    enabled: true
                },
                scrollbar: {
                    enabled: false
                }
            };

            var yAxis = 0;
            if (params.values.view_vol) {
                yAxis++;

                if (response.rows_2.length > 0) {
                    chart_paras.series.push({
                        type: 'column',
                        name: 'buy小量',
                        data: volume_3.sm,
                        yAxis: yAxis,
                        id: 'volume_3_sm',
                        grouping: true,
                        groupPadding: 0.2,
                        pointPadding: 0,
                        stacking: 'buy'
                    });
                    chart_paras.series.push({
                        type: 'column',
                        name: 'buy中量',
                        data: volume_3.md,
                        yAxis: yAxis,
                        id: 'volume_3_md',
                        grouping: true,
                        groupPadding: 0.2,
                        pointPadding: 0,
                        stacking: 'buy'
                    });
                    chart_paras.series.push({
                        type: 'column',
                        name: 'buy大量',
                        data: volume_3.lg,
                        yAxis: yAxis,
                        id: 'volume_3_lg',
                        grouping: true,
                        groupPadding: 0.2,
                        pointPadding: 0,
                        stacking: 'buy'
                    });

                    /*
                                       chart_paras.series.push({
                                           type: 'column',
                                           name: 'sell小量',
                                           data: volume_3.sm2,
                                           yAxis: yAxis,
                                           id: 'volume_3_sm2',
                                           grouping: true,
                                           groupPadding: 0.2,
                                           pointPadding: 0,
                                           stacking: 'sell'
                                       });
                                       chart_paras.series.push({
                                           type: 'column',
                                           name: 'sell中量',
                                           data: volume_3.md2,
                                           yAxis: yAxis,
                                           id: 'volume_3_md2',
                                           grouping: true,
                                           groupPadding: 0.2,
                                           pointPadding: 0,
                                           stacking: 'sell'
                                       });
                                       chart_paras.series.push({
                                           type: 'column',
                                           name: 'sell大量',
                                           data: volume_3.lg2,
                                           yAxis: yAxis,
                                           id: 'volume_3_lg2',
                                           grouping: true,
                                           groupPadding: 0.2,
                                           pointPadding: 0,
                                           stacking: 'sell'
                                       });
                    */
                } else {
                    chart_paras.series.push({
                        type: 'column',
                        name: '成交量',
                        data: volume,
                        yAxis: yAxis,
                        id: 'volume',
                    });
                }

                chart_paras.series.push({
                    type: 'line',
                    name: 'short',
                    data: volume_short_Line,
                    color: '#FFA500',  // 颜色：橙色
                    lineWidth: 2,
                    id: 'volume_short',
                    yAxis: yAxis
                });
                chart_paras.series.push({
                    type: 'line',
                    name: 'long',
                    data: volume_long_Line,
                    color: '#000000',  // 颜色：黑色
                    lineWidth: 2,
                    id: 'volume_long',
                    yAxis: yAxis
                });

                chart_paras.yAxis.push({
                    labels: {
                        align: 'right',
                        x: -3
                    },
                    title: {
                        text: '成交量'
                    },
                    top: (100 - chart_height * (view_num - yAxis + 1) + 1) + '%',
                    height: (chart_height - 1) + '%',
                    offset: 0,
                    lineWidth: 2,
                })
            }
            if (params.values.view_macd) {
                yAxis++;
                chart_paras.series.push(
                    {
                        type: 'line',
                        name: 'MACD线',
                        data: macd.macdLine,
                        color: '#FFA500', // 橙色
                        lineWidth: 2,
                        yAxis: yAxis,
                        id: 'MACD-Line',
                    });
                chart_paras.series.push({
                    type: 'line',
                    name: '信号线',
                    data: macd.signalLine,
                    color: '#000000',  // 颜色：黑色
                    lineWidth: 2,
                    yAxis: yAxis,
                    id: 'Signal-Line',
                });
                chart_paras.series.push({
                    type: 'column',
                    name: 'MACD柱',
                    data: macd_histogram,
                    yAxis: yAxis,
                    id: 'Histogram',
                    pointWidth: 4 // 设置柱状图宽度
                });

                chart_paras.yAxis.push({
                    labels: {
                        align: 'right',
                        x: -3
                    },
                    title: {
                        text: 'MACD'
                    },
                    top: (100 - chart_height * (view_num - yAxis + 1) + 1) + '%',
                    height: (chart_height - 1) + '%',
                    offset: 0,
                    lineWidth: 2,
                });
            }
            if (params.values.view_vmacd) {
                yAxis++;
                chart_paras.series.push({
                    type: 'line',
                    name: 'VMACD线',
                    data: vmacd.macdLine,
                    color: '#FFA500', // 橙色
                    lineWidth: 2,
                    yAxis: yAxis,
                    id: 'VMACD-Line',
                });
                chart_paras.series.push({
                    type: 'line',
                    name: '信号线',
                    data: vmacd.signalLine,
                    color: '#000000',  // 颜色：黑色
                    lineWidth: 2,
                    yAxis: yAxis,
                    id: 'VMACD-Signal-Line',
                });
                chart_paras.series.push({
                    type: 'column',
                    name: 'VMACD柱',
                    data: vmacd_histogram,
                    yAxis: yAxis,
                    id: 'VMACD-Histogram',
                    pointWidth: 4 // 设置柱状图宽度
                });

                chart_paras.yAxis.push({
                    labels: {
                        align: 'right',
                        x: -3
                    },
                    title: {
                        text: 'VMACD'
                    },
                    top: (100 - chart_height * (view_num - yAxis + 1) + 1) + '%',
                    height: (chart_height - 1) + '%',
                    offset: 0,
                    lineWidth: 2,
                });
            }
            if (params.values.view_vrsi) {
                yAxis++;
                chart_paras.series.push({
                    type: 'line',
                    name: 'VRSI',
                    data: vrsi,
                    color: '#FFA500',  // 快速线 橙色
                    lineWidth: 2,
                    yAxis: yAxis,
                    id: 'VRSI'
                });
                chart_paras.yAxis.push({
                    labels: {
                        align: 'right',
                        x: -3
                    },
                    title: {
                        text: 'VRSI'
                    },
                    top: (100 - chart_height * (view_num - yAxis + 1) + 1) + '%',
                    height: (chart_height - 1) + '%',
                    offset: 0,
                    lineWidth: 2,
                });
            }
            if (params.values.view_ad) {
                yAxis++;
                chart_paras.series.push({
                    type: 'line',
                    name: 'AD',
                    data: ad,
                    color: '#FFA500',  // 快速线 橙色
                    lineWidth: 2,
                    yAxis: yAxis,
                    id: 'AD'
                });
                chart_paras.yAxis.push({
                    labels: {
                        align: 'right',
                        x: -3
                    },
                    title: {
                        text: 'AD'
                    },
                    top: (100 - chart_height * (view_num - yAxis + 1) + 1) + '%',
                    height: (chart_height - 1) + '%',
                    offset: 0,
                    lineWidth: 2,
                });
            }
            if (params.values.view_ser) {
                yAxis++;
                chart_paras.series.push({
                    type: 'line',
                    name: '突击能量比',
                    data: ser,
                    color: '#FFA500',  // 快速线 橙色
                    lineWidth: 2,
                    yAxis: yAxis,
                    id: 'SER'
                });
                chart_paras.yAxis.push({
                    labels: {
                        align: 'right',
                        x: -3
                    },
                    title: {
                        text: '突击能量比'
                    },
                    top: (100 - chart_height * (view_num - yAxis + 1) + 1) + '%',
                    height: (chart_height - 1) + '%',
                    offset: 0,
                    lineWidth: 2,
                });
            }
            if (params.values.view_pva) {
                yAxis++;
                chart_paras.series.push({
                    type: 'line',
                    name: '量价加速度',
                    data: pva,
                    color: '#FFA500',  // 快速线 橙色
                    lineWidth: 2,
                    yAxis: yAxis,
                    id: 'PVA'
                });
                chart_paras.yAxis.push({
                    labels: {
                        align: 'right',
                        x: -3
                    },
                    title: {
                        text: '量价加速度'
                    },
                    top: (100 - chart_height * (view_num - yAxis + 1) + 1) + '%',
                    height: (chart_height - 1) + '%',
                    offset: 0,
                    lineWidth: 2,
                });
            }
            if (params.values.view_bf) {
                yAxis++;
                chart_paras.series.push({
                    type: 'line',
                    name: '资金聚焦度',
                    data: bf,
                    color: '#FFA500',  // 快速线 橙色
                    lineWidth: 2,
                    yAxis: yAxis,
                    id: 'BF'
                });
                chart_paras.yAxis.push({
                    labels: {
                        align: 'right',
                        x: -3
                    },
                    title: {
                        text: '资金聚焦度'
                    },
                    top: (100 - chart_height * (view_num - yAxis + 1) + 1) + '%',
                    height: (chart_height - 1) + '%',
                    offset: 0,
                    lineWidth: 2,
                });
            }
            if (params.values.view_kdj) {
                yAxis++;
                chart_paras.series.push({
                    type: 'line',
                    name: 'KDJ K',
                    data: kLine,
                    color: '#FFA500',  // 快速线 橙色
                    lineWidth: 2,
                    yAxis: yAxis,
                    id: 'KDJ-K'
                });
                chart_paras.series.push({
                    type: 'line',
                    name: 'KDJ D',
                    data: dLine,
                    color: '#000000',  //慢速线 黑色
                    lineWidth: 2,
                    yAxis: yAxis,
                    id: 'KDJ-D'
                });
                chart_paras.series.push({
                    type: 'line',
                    name: 'KDJ J',
                    data: jLine,
                    color: '#1C86EE',  // 超快线 蓝色
                    lineWidth: 2,
                    yAxis: yAxis,
                    id: 'KDJ-J'
                });

                chart_paras.yAxis.push({
                    labels: {
                        align: 'right',
                        x: -3
                    },
                    title: {
                        text: 'KDJ'
                    },
                    top: (100 - chart_height * (view_num - yAxis + 1) + 1) + '%',
                    height: (chart_height - 1) + '%',
                    offset: 0,
                    lineWidth: 2,
                });
            }
            if (params.values.view_cci) {
                console.log('cciPeriodLine:', cciPeriodLine); // 调试日志
                yAxis++;
                chart_paras.series.push({
                    type: 'line',
                    name: 'CCI',
                    data: cciPeriodLine,
                    color: '#000000', // 红色
                    lineWidth: 2,
                    yAxis: yAxis,
                    id: 'CCI'
                });
                chart_paras.yAxis.push({
                    labels: {
                        align: 'right',
                        x: -3
                    },
                    title: {
                        text: 'CCI'
                    },
                    top: (100 - chart_height * (view_num - yAxis + 1) + 1) + '%',
                    height: (chart_height - 1) + '%',
                    offset: 0,
                    lineWidth: 1,
                    plotLines: [
                        {
                            value: 100,
                            color: 'red',
                            dashStyle: 'Dashed',
                            width: 2,
                            label: {
                                text: '100',
                                align: 'left',
                                x: 10
                            }
                        },
                        {
                            value: -100,
                            color: 'green',
                            dashStyle: 'Dashed',
                            width: 2,
                            label: {
                                text: '-100',
                                align: 'left',
                                x: 10
                            }
                        }
                    ]
                })
            }
            if (params.values.view_adx) {
                yAxis++;
                chart_paras.series.push({
                    type: 'line',
                    name: 'ADX',
                    data: adxPeriodLine[0],
                    color: '#FF0000', // 红色
                    lineWidth: 2,
                    dashStyle: 'Dash',
                    yAxis: yAxis,
                    id: 'ADX'
                });

                chart_paras.series.push(
                    {
                        type: 'line',
                        name: '-DI',
                        data: adxPeriodLine[1],
                        color: '#FFA500', // 橙色
                        lineWidth: 2,
                        yAxis: yAxis,
                        id: 'ADX-DI',
                    });
                chart_paras.series.push({
                    type: 'line',
                    name: '-DI',
                    data: adxPeriodLine[2],
                    color: '#000000',  // 颜色：黑色
                    lineWidth: 2,
                    yAxis: yAxis,
                    id: 'ADX-DI2',
                });

                chart_paras.yAxis.push({
                    labels: {
                        align: 'right',
                        x: -3
                    },
                    title: {
                        text: 'ADX'
                    },
                    top: (100 - chart_height * (view_num - yAxis + 1) + 1) + '%',
                    height: (chart_height - 1) + '%',
                    offset: 0,
                    lineWidth: 2,
                });
            }

            $("#view_stockpage").attr("href", "https://stockpage.10jqka.com.cn/" + response.symbol + "/");
            const dg_title = response.name + '(' + response.ts_code + ')';
            var $iframe = $.yqWinPopEdit("iframe");
            if ($iframe.length > 0) {
                $iframe.data("$dg").dialog("setTitle", dg_title);
            }
            $('title').html(dg_title);

            // 创建图表实例时添加 BOLL 系列
            const h_ = window.innerHeight - 31;
            $('#highcharts-chart').css({
                "margin-top": "0",
                "height": `${h_}px`
            });
            params.chart = Highcharts.stockChart('highcharts-chart', chart_paras);

            if (!params.values.ma1_toggle) {
                params.toggleSeries('ma_day', false);
            }
            if (!params.values.boll_toggle) {
                params.toggleSeries('BOLL-MID', false);
                params.toggleSeries('BOLL-UPPER', false);
                params.toggleSeries('BOLL-LOWER', false);
            }
            if (!params.values.ene_toggle) {
                params.toggleSeries('ENE-MID', false);
                params.toggleSeries('ENE-UPPER', false);
                params.toggleSeries('ENE-LOWER', false);
            }
            if (!params.values.ma_toggle) {
                params.toggleSeries('ma_short', false);
                params.toggleSeries('ma_long', false);
            }

            params.is_edit(true);
        }
    </script>
</body>

</html>